//
//  XJTixianCell.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/24.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJTixianCell.h"
@interface XJTixianCell()
@property (weak, nonatomic) IBOutlet UIImageView *iconIV;
@property (weak, nonatomic) IBOutlet UILabel *nameLB;

@end
@implementation XJTixianCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.iconIV.layer.masksToBounds = YES;
    self.iconIV.layer.cornerRadius = 3;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

//0：支付宝；1：银行卡
- (void)setModel:(XJTiXianModel *)model {
    NSString *iconStr = @"";
    if ([model.type isEqualToNumber:@(0)]) {
        iconStr = @"pay_alipay";
        
        self.nameLB.text = [NSString stringWithFormat:@"支付宝 %@%@",model.name,[self damaWithNum:model.cardNum]];

    }else {
        iconStr = @"pay_card";
        self.nameLB.text = [NSString stringWithFormat:@"银行卡 %@%@",model.name,[self damaWithNum:model.cardNum]];
    }
    
    self.iconIV.image = [UIImage imageNamed:iconStr];
    
    
    
    
    //cell单选
    if (model.check) {
        self.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"selected_on"]];
    }else {
        self.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"selected_off"]];
    }
}


- (NSString *)damaWithNum:(NSString *)num {
    
    NSInteger count = num.length;
    if (count < 7) {
        return num;
    }
    
    //支付宝:1583****345
    //银行卡:1788********453
    NSInteger lead = 4;
    NSInteger trail = 3;
    
    NSRange leadingRange = NSMakeRange(0, lead);
    NSRange trailingRagne = NSMakeRange(count - trail, trail);
    
    NSString *leadingStr = [num substringWithRange:leadingRange];
    NSString *trailingStr = [num substringWithRange:trailingRagne];
    
    
    //打码
    NSMutableString *middleStr = [NSMutableString string];
    for (NSInteger i =0; i<count - trail; i++) {
        [middleStr appendFormat:@"*"];
    }
    
    NSString *resultStr = [NSString stringWithFormat:@"%@%@%@",leadingStr,middleStr,trailingStr];
    
    return resultStr;
}




@end
